package db

import (
	"fmt"
	"pmservice/graph/model"
	"time"
)

type Token struct {
	ID       uint
	Token    string
	CreateAt time.Time
	ExpireAt time.Time
	UserUID  string
	UserName string
	UserType string
}

// GORM使用结构体名的蛇形命名作为表名。对于结构体Xxx，根据约定，其表名为Xxxs
// TableName会将表名重写
func (Token) TableName() string {
	return "token"
}

func (t *Token) ToGQL() *model.Token {
	return &model.Token{
		Token:    t.Token,
		Createat: t.CreateAt,
		Expireat: t.ExpireAt,
		Useruid:  t.UserUID,
		Username: t.UserName,
		Usertype: fmt.Sprint(t.UserType),
	}
}
